version 14.2
set more off

**************************************************************************************************************
* THIS ROUTINE GENERATES TABLE I OF WASEEM (2020) ROLE OF WITHHOLDING ...
**************************************************************************************************************

#d					;
matrix 				input table=(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
								 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
#d					cr

*-----------------------
/* FORWARD LINKAGES */
*-----------------------

/* MANUFACTURERS */

use				"$project_data\InvSum_06_12_S.dta",clear	
keep			if fy>2007 & fy<2011
keep			if seller_business_sts=="1"
g				seller_ind=substr(seller_item_cd,1,4)
g				ind=real(seller_ind)
drop			if ind<1600
drop			if ind>=2500 & ind<2800
drop			if salestax_amount>=01e+12 & salestax_amount<.
g				buyer_ind=substr(buyer_item_cd,1,4)
g				elect=(buyer_ind=="2716")
g				gas=((buyer_regno=="0204902800119" | buyer_regno=="0391999996719")) //Identifed from firms' purchases from SUI NORTHERN AND SUI SOUTHERN
g				energy=elect==1 | gas==1  
g				bus=0
replace			bus=1 if buyer_business_sts=="1"
replace			bus=2 if buyer_business_sts=="2"
replace			bus=3 if buyer_business_sts=="3"
replace			bus=4 if buyer_business_sts=="4" | buyer_business_sts=="5" | buyer_business_sts=="6"
replace			bus=5 if energy==1
replace			bus=6 if buyer_business_sts=="8"
bys				fy bus:egen totvat_bus=sum(salestax_amount)
bys				fy:egen totvat=sum(salestax_amount)
g				share_vat=(totvat_bus/totvat)*100
duplicates 		drop fy bus, force
keep			fy bus share_
reshape			wide share_, i(bus) j(fy)
local			i=1
local			j=1
forvalues		b=1/6 {
forvalues		y=2008/2010 {
qui					sum share_vat`y' if bus==`b'
matrix				table[`i',`j']=r(mean)
local				j=`j'+1
}
local				i=`i'+1
local				j=1
}

/* IMPORTERS */

use				"$project_data\InvSum_06_12_S.dta",clear	
keep			if fy>2007 & fy<2011
keep			if seller_business_sts=="2"
g				seller_ind=substr(seller_item_cd,1,4)
g				ind=real(seller_ind)
drop			if ind<1600
drop			if ind>=2500 & ind<2800
drop			if salestax_amount>=01e+09 & salestax_amount<.
g				buyer_ind=substr(buyer_item_cd,1,4)
g				elect=(buyer_ind=="2716")
g				gas=((buyer_regno=="0204902800119" | buyer_regno=="0391999996719")) //Identifed from firms' purchases from SUI NORTHERN AND SUI SOUTHERN
g				energy=elect==1 | gas==1  
g				bus=0
replace			bus=1 if buyer_business_sts=="1"
replace			bus=2 if buyer_business_sts=="2"
replace			bus=3 if buyer_business_sts=="3"
replace			bus=4 if buyer_business_sts=="4" | buyer_business_sts=="5" | buyer_business_sts=="6"
replace			bus=5 if energy==1
replace			bus=6 if buyer_business_sts=="8"
bys				fy bus:egen totvat_bus=sum(salestax_amount)
bys				fy:egen totvat=sum(salestax_amount)
g				share_vat=(totvat_bus/totvat)*100
duplicates 		drop fy bus, force
keep			fy bus share_
reshape			wide share_, i(bus) j(fy)
local			i=1
local			j=4
forvalues		b=1/6 {
forvalues		y=2008/2010 {
qui					sum share_vat`y' if bus==`b'
matrix				table[`i',`j']=r(mean)
local				j=`j'+1
}
local				i=`i'+1
local				j=4
}

*-----------------------
/* BACKWARD LINKAGES */
*-----------------------

/* MANUFACTURERS */

use				"$project_data\InvSum_06_12_P.dta",clear	
keep			if fy>2007 & fy<2011
keep			if buyer_business_sts=="1"
g				buyer_ind=substr(buyer_item_cd,1,4)
g				ind=real(buyer_ind)
drop			if ind<1600
drop			if ind>=2500 & ind<2800
drop			if salestax_amount>=01e+12 & salestax_amount<.
g				seller_ind=substr(seller_item_cd,1,4)
g				elect=(seller_ind=="2716")
g				gas=((seller_regno=="0204902800119" | seller_regno=="0391999996719")) //Identifed from firms' purchases from SUI NORTHERN AND SUI SOUTHERN
g				energy=elect==1 | gas==1 
g				bus=0
replace			bus=1 if seller_business_sts=="1"
replace			bus=2 if seller_business_sts=="2"
replace			bus=3 if seller_business_sts=="3"
replace			bus=4 if seller_business_sts=="4" | seller_business_sts=="5" | seller_business_sts=="6"
replace			bus=5 if energy==1
replace			bus=6 if seller_business_sts=="8"
bys				fy bus:egen totvat_bus=sum(salestax_amount)
bys				fy:egen totvat=sum(salestax_amount)
g				share_vat=(totvat_bus/totvat)*100
duplicates 		drop fy bus, force
keep			fy bus share_
reshape			wide share_, i(bus) j(fy)
local			i=7
local			j=1
forvalues		b=1/6 {
forvalues		y=2008/2010 {
qui					sum share_vat`y' if bus==`b'
matrix				table[`i',`j']=r(mean)
local				j=`j'+1
}
local				i=`i'+1
local				j=1
}

/* IMPORTERS */

use				"$project_data\InvSum_06_12_P.dta",clear	
keep			if fy>2007 & fy<2011
keep			if buyer_business_sts=="2"
g				buyer_ind=substr(buyer_item_cd,1,4)
g				ind=real(buyer_ind)
drop			if ind<1600
drop			if ind>=2500 & ind<2800
drop			if salestax_amount>=01e+09 & salestax_amount<.
g				seller_ind=substr(seller_item_cd,1,4)
g				elect=(seller_ind=="2716")
g				gas=((seller_regno=="0204902800119" | seller_regno=="0391999996719")) //Identifed from firms' purchases from SUI NORTHERN AND SUI SOUTHERN
g				energy=elect==1 | gas==1 
g				bus=0
replace			bus=1 if seller_business_sts=="1"
replace			bus=2 if seller_business_sts=="2"
replace			bus=3 if seller_business_sts=="3"
replace			bus=4 if seller_business_sts=="4" | seller_business_sts=="5" | seller_business_sts=="6"
replace			bus=5 if energy==1
replace			bus=6 if seller_business_sts=="8"
bys				fy bus:egen totvat_bus=sum(salestax_amount)
bys				fy:egen totvat=sum(salestax_amount)
g				share_vat=(totvat_bus/totvat)*100
duplicates 		drop fy bus, force
keep			fy bus share_
reshape			wide share_, i(bus) j(fy)
local			i=7
local			j=4
forvalues		b=1/6 {
forvalues		y=2008/2010 {
qui					sum share_vat`y' if bus==`b'
matrix				table[`i',`j']=r(mean)
local				j=`j'+1
}
local				i=`i'+1
local				j=4
}

/* IMPORTED INPUTS */

use				"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep            if business_sts=="1" | business_sts=="2"
keep			if fy>1997 & fy<=2000
g				ind=real(substr(item_cd,1,4))
drop			if ind<1600
drop			if ind>=2500 & ind<2800
g				treat=business_sts=="1"
bys				treat:egen totinput=sum(input)
bys				treat:egen totpurch=sum(tot_purch)
bys				treat:egen totimp=sum(impopurch)
g 				ratio=totimp/totpurch
qui				sum ratio if treat==1
local			ratio_m=1-r(mean)
qui				sum ratio if treat==0
local			ratio_i=1-r(mean)

/* EXPORTING THE TABLE */ 

svmat			table
keep			tab*
keep			if _n<=12
drop			table7-table18
g				c20=""
replace			c20="Manufacturer" in 1
replace			c20="Importer" in 2
replace			c20="Exporter" in 3
replace			c20="Distributor, Wholesaler, and Retailer" in 4
replace			c20="Energy" in 5
replace			c20="Services" in 6
replace			c20="Manufacturer" in 7
replace			c20="Importer" in 8
replace			c20="Exporter" in 9
replace			c20="Distributor, Wholesaler, and Retailer" in 10
replace			c20="Energy" in 11
replace			c20="Services" in 12
forvalues		r=7/12 {
forvalues		c=1/3 {
replace			table`c'=table`c'*`ratio_m' in `r'
}
}
forvalues		r=7/12 {
forvalues		c=4/6 {
replace			table`c'=table`c'*`ratio_i' in `r'
}
}
forvalues		c=1/6 {
g				c`c'=string(table`c',"%9.1f")
}
forvalues 		s=1/15 {
g				s`s'="&"
}
g				l="\\\\"
order 			c20 s1 c1 s2 c2 s3 c3 s4 s5 c4 s6 c5 s7 c6 l
browse 			c20 s1 c1 s2 c2 s3 c3 s4 s5 c4 s6 c5 s7 c6 l

